package com.liqing.movecomment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.liqing.movecomment.entity.MoveTag;
import com.liqing.movecomment.dao.MoveTagDao;
import com.liqing.movecomment.service.MoveTagService;
import org.springframework.stereotype.Service;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


@Transactional
@Service("moveTagService")
public class MoveTagServiceImpl implements MoveTagService {
    @Resource
    private MoveTagDao moveTagDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public MoveTag queryById(Integer id) {
        return this.moveTagDao.selectById(id);
    }

    /**
     * 分页查询
     *
     * @param page 页码
     * @param size 页大小
     * @return 查询结果
     */
    @Override
    public PageInfo<MoveTag> queryAll(Integer page, Integer size) {
        PageHelper.startPage(page, size);
        LambdaQueryWrapper<MoveTag> wrapper = new LambdaQueryWrapper<>();

        List<MoveTag> list = this.moveTagDao.selectList(wrapper);

        return new PageInfo<>(list);
    }

    /**
     * 新增数据
     *
     * @param moveTag 实例对象
     * @return 实例对象
     */
    @Override
    public MoveTag insert(MoveTag moveTag) {
        this.moveTagDao.insert(moveTag);
        return moveTag;
    }

    /**
     * 修改数据
     *
     * @param moveTag 实例对象
     * @return 实例对象
     */
    @Override
    public MoveTag update(MoveTag moveTag) {
        this.moveTagDao.updateById(moveTag);
        return this.moveTagDao.selectById(moveTag.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.moveTagDao.deleteById(id) > 0;
    }
}
